package cn.tedu.sp02.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.service.ItemService;
import cn.tedu.web.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

public class ItemController {

    @Autowired
    private ItemService itemService;

    //获取订单的商品列表
    /*JsonResult 用来封装返回给客户端的信息
    * */
    @GetMapping
    public JsonResult<List<Item>> getItem(@PathVariable String orderId){
        List<Item> items = itemService.getItems(orderId);
        JsonResult r = JsonResult.ok().data(items);
        return r;
    }

    @PostMapping("/decreaseNumber")
    public JsonResult<?> decreaseNumber(@RequestBody List<Item> items){
        itemService.decreaseNumber(items);
        return JsonResult.ok().msg("减少商品库存成功");
    }

}
